<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

</head>
<div id="app">
    <input type="text" v-model="inputValue" />
    <button v-on:click="handBtnClick">提交</button>
    <ul>
        <todo-item v-bind:content="item" v-for="(item,index) in list" @delete="handleItemDelete"></todo-item>
    </ul>
</div>

<body>
    <script>
        //全局组件
        // Vue.component("TodoItem", {
        //     props: ['content'],
        //     template: '<li>{{content}}</li>'
        // })

        // 单个组件
        var TodoItem = {
            props: ['content', 'index'],
            template: '<li @click="handleItemClick">{{content}}</li>',
            methods: {
                handleItemClick: function() {
                    this.$emit("delete");
                }
            }
        }
        var app = new Vue({
            el: '#app',
            components: {
                TodoItem: TodoItem
            },
            data: {
                list: ['第一课内容', '第二课内容', '333'],
                inputValue: ''
            },
            methods: {
                handBtnClick: function() {
                    this.list.push(this.inputValue)
                    this.inputValue = ''
                },
                handleItemDelete: function(index) {
                    // this.list = []
                    this.list.splice(index, 1)
                }
            }
        })
    </script>
</body>

</html>